mui.init();

var dataInfo = hui.winInfo();
hui('#startBanner').find(".hui-swipe-item").css({
	height: dataInfo.height + 'px'
});
//hui('#startBanner').show();
//hui('#hui-start-banner-close').show();
var swipe = new huiSwpie('#startBanner');
swipe.autoPlay = true;
swipe.loop = false;
swipe.run();

//预加载
//hui.create('detail.html');

//关闭广告
function huiStartBannerClose() {
	hui('#startBanner').remove();
	
	//初始化
	hui.h5Loading(false, '加载中...',{round:2, padding:'20px', textalign:'right'});
	for(var i = 1; i < 9; i++) {
		//点击新闻列表，打开新闻详情
		ajaxData(i, 1);
		mui('#list_'+i+'_ul').on('tap', 'li', function() {
			open_new_detail(this.getAttribute('href-id'), this.getAttribute('tableNum'));
		});
	}
	hui.tab('.hui-tab');
	hui.h5Loading(true);
	
}
//tab 获取信息
function ajaxData(type, page) {
	var typeID = hui('#list_' + type).find("ul");
	hui.ajax({
		url: 'http://api.dagoogle.cn/news/get-news?tableNum=' + type + '&pagesize=20&page=' + page,
		backType: 'JSON',
		async: false,
		beforeSend: function() {
			
		},
		complete: function() {
			
		},
		success: function(msg) {
			if(msg.status == 200) {
				var htmlData = '';
				var num = msg.data.length;
				for(var i = 0; i < num; i++) {
					//htmlData += '<li>' + msg.data[i]['digest'] + '</li>';
					var li = document.createElement('li');
					li.innerHTML = msg.data[i]['digest'];
					li.setAttribute('href-id', msg.data[i]['news_id']);
					li.setAttribute('tableNum', type);
					hui(li).appendTo(typeID);
				}
				//typeID.html(htmlData);
			} else {
				hui.iconToast('读取消息失败', 'warn');
			}

		},
		error: function(e) {
			hui.iconToast('读取消息失败', 'warn');
		}
	});
}

//打開新的窗口
function open_new_detail(id, tableNum) {
	hui.open('detail.html', {}, true, {
		newID: id,
		tableNum: tableNum
	});
}